<?php

/**
 * 前台 酒店图片 模块 Controller
 * ============================================================================
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zwt007 $  <zwttmac@qq.com>
 * $Id: hotelpic.php 145 2013-01-22 17:54:45Z zwt007 $
 * http://www.t-mac.org；
 */
class hotelpicAction extends Action
{

    public function _init()
    {
        $this->assign('action', $_GET['TMAC_ACTION']);
    }

    public function index()
    {
        $cache = CacheDriver::getInstance('Memcached');
        $cache->set('key', 'valuereplace11',600);
        $val = $cache->get('key');
        echo $val; //输出结果为“value”           
//        $this->V('post');
    }

    public function upload()
    {
        $this->V('hotelpic_upload');
    }

    public function upsave()
    {
        $filename = $this->getParam('filename', 'pic');
        //上传图片并返回图片url
        $data_dir = STATIC_ROOT . 'uploadfiles/test';
        $dir_array['data_dir'] = $data_dir;
        $dir_array['thumb_dir'] = '/uploadfiles/litimg/';
        $image = Tmac::plugin('Image', $dir_array);
        $upload_image = $image->upload_image($filename, 0);
        if ($upload_image === false) {
//            $rs = $image->error_msg();
            $error = $image->error_msg();
            $url = '';
        } else {
            $url = $upload_image;
            $error = '';
        }
        $obj = Tmac::plugin('ImageWater', $url);
        //类型：0为文字水印、1为图片水印
        $obj->waterType = 0;
        //水印透明度，值 越小透明度越高
        $obj->transparent = 50;
        //水印文字 
        $obj->waterStr = '生日快乐';
        //水印图片        
        //$obj->waterImg = 'D:\Web\Site\tblog\Public\uploadfiles\upload\day_111114\201111140741585970.jpg';//水印图片
        //文字字体大小 
        $obj->fontSize = 14;
        //水印文字颜色（RGB） 
        $obj->fontColor = array(255, 255, 100);
        //字体文件 
        $obj->fontFile = 'c:/windows/fonts/YaHei.Consolas.1.11b.ttf';
        //输出水印图片文件覆盖到输入的图片文件         
        $obj->output();
        echo "{";
        echo "error: '" . $error . "',\n";
        echo "url: '" . $url . "'\n";
        echo "}";
    }

    public function water()
    {
//        header("Content-type: image/jpeg");
        $obj = Tmac::plugin('ImageWater', 'D:\Web\Site\tblog\Public\uploadfiles\test2012-01\201201160039442592.jpg');
        //类型：0为文字水印、1为图片水印
        $obj->waterType = 1;
        //水印透明度，值 越小透明度越高
        $obj->transparent = 50;
        //水印文字 
        $obj->waterStr = '生日快乐';
        //水印图片        
        $obj->waterImg = 'D:\Web\Witkey\wk\mrcody\img\logo.gif'; //水印图片
        //文字字体大小 
        $obj->fontSize = 14;
        //水印文字颜色（RGB） 
        $obj->fontColor = array(255, 255, 100);
        //字体文件 
        $obj->fontFile = 'c:/windows/fonts/YaHei.Consolas.1.11b.ttf';
        //输出水印图片文件覆盖到输入的图片文件         
        $obj->output();
    }

}